<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>退费记录管理</title>
    <%@include file="../../sys_common_head.jsp"%>
</head>
<body class="pear-container">


<!-- 查询条件 -->

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">身份证号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="stuIdcard" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">学生姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="stuName" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">联系人</label>
                    <div class="layui-input-inline">
                        <input type="text" name="contacts" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">联系电话</label>
                    <div class="layui-input-inline">
                        <input type="text" name="phone" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-inline">
                        <select name="status" id="status">
                            <option value="">请选择</option>
                            <option value="1">待审核</option>
                            <option value="2">审核通过</option>
                            <option value="3">审核不通过</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="data-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card">
    <div class="layui-card-body">
        <table id="data-table" lay-filter="data-table"></table>
    </div>
</div>
</body>

<!-- 工具栏 -->
<script type="text/html" id="data-toolbar">

</script>

<!-- 每行操作栏 -->
<script type="text/html" id="data-bar">
    {{#if (d.status != '2') { }}
    <button class="pear-btn pear-btn-primary pear-btn-sm" title="审核" lay-event="edit"><i class="layui-icon layui-icon-rmb"></i>
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-sm" title="删除" lay-event="remove"><i class="layui-icon layui-icon-delete"></i>
    {{# } }}
    </button>
</script>


<script>
    layui.use(['table', 'form', 'jquery','common'], function() {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;

        let MODULE_PATH = "<%=request.getContextPath()%>/student/refund/";

        let cols = [
            [
                {field: 'graduateNo', title: '准考证号'},
                {field: 'stuIdcard', title: '身份证号'},
                {field: 'stuName', title: '学生姓名'},
                {field: 'contacts', title: '联系人'},
                {field: 'fee', title: '金额'},
                {field: 'openBank', title: '开户行'},
                {field: 'bankCard', title: '银行卡号'},
                {field: 'fpUrl', title: '发票',templet: "<div><img src=\"<%=request.getContextPath()%>/upload/{{d.fpUrl}}\" alt=\"\" style=\"width:80px; height:80px;\" onclick=\"showBigImage(this)\"\"></div>"},
                {field: 'phone', title: '联系电话'},
                {field: 'status', title: '状态',templet:function(d){
                        if(d.status == 1){
                            return "待审核";
                        }else if(d.status == 2){
                            return "审核通过";
                        }else{
                            return "审核不通过";
                        }
                }},
                {title: '操作', fixed: 'right', width: 165, align:'center', toolbar: '#data-bar'}
            ]
        ]

        table.render({
            elem: '#data-table',
            url: MODULE_PATH + 'list',
            page: true,
            method:'post',
            cols: cols,
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            toolbar: '#data-toolbar'
        });

        table.on('tool(data-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
        });

        table.on('toolbar(data-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        form.on('submit(data-query)', function (data) {
            table.reload('data-table', {where: data.field})
            return false;
        });

        window.add = function() {
            layer.open({
                type: 2,
                title: '新增数据',
                shade: 0.1,
                area: [common.isModile()?'100%':'500px', common.isModile()?'100%':'400px'],
                content: MODULE_PATH + 'add'
            });
        }

        window.edit = function(obj) {
            // layer.open({
            //     type: 2,
            //     title: '修改数据',
            //     shade: 0.1,
            //     area: ['500px', '400px'],
            //     content: MODULE_PATH + 'edit?id=' + obj.data['id']
            // });
            //eg1
            layer.confirm('确定要审核该数据？', {
                btn: ['审核通过', '审核不通过', '取消']
                ,btn3: function(index, layero){
                    //按钮【按钮三】的回调
                }
            }, function(index, layero){

                window.auditRefund(index,obj.data['id'],2)

            }, function(index){
                window.auditRefund(index,obj.data['id'],3)
            });
        }

        window.auditRefund = function(index,id,status){
            layer.close(index);
            let loading = layer.load();
            $.ajax({
                url: MODULE_PATH + "auditRefund",
                dataType: 'json',
                type: 'post',
                data:{
                    id:id,
                    status:status
                },
                success: function(result) {
                    layer.close(loading);
                    if (result.code == 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            window.refresh()
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
        }

        window.remove = function(obj) {
            layer.confirm('确定要删除该数据？', {
                icon: 3,
                title: '提示'
            }, function(index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove/" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function(result) {
                        layer.close(loading);
                        if (result.code == 0) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000
                            }, function() {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }

        window.batchRemove = function(obj) {

            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            let ids = "";
            for (let i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }

            layer.confirm('确定要删除这些数据？', {
                icon: 3,
                title: '提示'
            }, function(index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "removeBatch/" + ids,
                    dataType: 'json',
                    type: 'delete',
                    success: function(result) {
                        layer.close(loading);
                        if (result.code == 0) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000
                            }, function() {
                                table.reload('data-table');
                            });
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                })
            });
        }

//显示大图片
        window.showBigImage = function (e) {
            console.log(e)
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                shadeClose: true, //点击阴影关闭
                area: ['600px', '600px'], //宽高
                content: "<img style='width: 100%' src=" + $(e).attr('src') + " />"
            });
        }
        window.refresh = function () {
            table.reload('data-table');
        }
    })
</script>
</html>